package com.wangp.mywrite.inwork.sentinel._2_annotaion;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/***
 * @author wangpeng
 * @since 2022-03-28  15:08
 */
@RestController
public class SentinelController {


    @GetMapping("test")
    @SentinelResource(value = "annotationSentinel", blockHandler = "exceptionHandler")
    public String test1(@RequestParam("id") long id) {
        return "id = " + id;
    }

    /*** Block 异常处理函数，参数最后多一个 BlockException，其余与原函数一致. */
    private String exceptionHandler(long s, BlockException ex) {
        // Do some log here.
        return "Oops, error occurred at " + s;
    }
}
